const XLSX = require('xlsx');
const path = require('path');

// 读取Excel文件
const filePath = path.join(__dirname, '..', 'myMoney.xls');
console.log('Reading file:', filePath);

try {
  const workbook = XLSX.readFile(filePath);
  
  // 获取所有工作表名称
  console.log('Sheet names:', workbook.SheetNames);
  
  // 读取第一个工作表
  const firstSheetName = workbook.SheetNames[0];
  console.log('First sheet name:', firstSheetName);
  
  const worksheet = workbook.Sheets[firstSheetName];
  
  // 将工作表转换为JSON
  const jsonData = XLSX.utils.sheet_to_json(worksheet, {header: 1});
  
  // 显示前几行数据
  console.log('First 10 rows of data:');
  for (let i = 0; i < Math.min(10, jsonData.length); i++) {
    console.log(`Row ${i + 1}:`, jsonData[i]);
  }
  
  console.log(`Total rows: ${jsonData.length}`);
  
  // 如果有列标题，显示列标题
  if (jsonData.length > 0) {
    console.log('Column headers:', jsonData[0]);
  }
} catch (error) {
  console.error('Error reading Excel file:', error.message);
}